#include <iostream>
#include <vector>
#include <string>

bool isPrime(int x) {
    bool a = true;
    for (int i = 2; i < x; i++) {
        if (x % i == 0) {
            a = false;
        }
    }
    return a;
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::vector<int> n1;
    int num = 0;
    bool wi = false;
    std::vector<int> pr;
    std::vector<int> pr1;
    
    std::vector<std::string> n;
    std::string word = "";
    for (char c : input) {
        if (c == ' ') {
            n.push_back(word);
            word = "";
        } else {
            word += c;
        }
    }
    n.push_back(word);
    
    if (n.size() == 3) {
        for (int i = 0; i < n.size(); i++) {
            if (n[i] == "zero") {
                n1.push_back(0);
            } else if (n[i] == "one") {
                n1.push_back(1);
            } else if (n[i] == "two") {
                n1.push_back(2);
            } else if (n[i] == "three") {
                n1.push_back(3);
            } else if (n[i] == "four") {
                n1.push_back(4);
            } else if (n[i] == "five") {
                n1.push_back(5);
            } else if (n[i] == "six") {
                n1.push_back(6);
            } else if (n[i] == "seven") {
                n1.push_back(7);
            } else if (n[i] == "eight") {
                n1.push_back(8);
            } else if (n[i] == "nine") {
                n1.push_back(9);
            } else {
                wi = true;
            }
        }
        
        for (int k = 0; k < 3; k++) {
            if (!wi) {
                if (k == 0) {
                    num += n1[k] * 100;
                }
                if (k == 1) {
                    num += n1[k] * 10;
                }
                if (k == 2) {
                    num += n1[k];
                }
            }
        }
        
        for (int y = num + 1; y < num + 100; y++) {
            bool a = isPrime(y);
            if (a) {
                pr.push_back(y);
            }
        }
        
        for (int q = 1; q < num; q++) {
            bool a = isPrime(q);
            if (a) {
                pr1.push_back(q);
            }
        }
    } else {
        wi = true;
    }
    
    if (wi) {
        std::cout << "Wrong input" << std::endl;
    } else {
        if ((num - pr1.back()) > (pr[0] - num)) {
            std::cout << pr[0] << std::endl;
        } else {
            std::cout << pr1.back() << std::endl;
        }
    }
    
    return 0;
}